package com.gadarts.parashoot.utils;

import java.util.HashMap;
import java.util.Random;

import android.util.Log;

import com.gadarts.parashoot.GameModel;

public class Utils {

	// Print a log.
	public static void log(String string) {
		Log.i("!", string);
	}
	
	public static void logWarning(String string) {
		Log.w("!", string);
	}

	public static void log(int number) {
		Log.i("!", Integer.toString(number));
	}

	public static void log(float number) {
		Log.i("!", Float.toString(number));
	}

	// Creates a new timer with given name.
	public static String setTimer(GameModel model, String name) {
		HashMap<String, Long> timers = model.getTimers();
		int count = 0;
		String newName = name + Integer.toString(count);
		// Find an available name.
		while (timers.containsKey(newName)) {
			count++;
			newName = name + Integer.toString(count);
		}
		model.addTimer(newName);
		return newName;
	}

	// Updates a given timer to current time.
	public static void updateTimer(GameModel model, String name) {
		model.addTimer(name);
	}

	// Checks if a given timer's up.
	public static boolean checkTiming(GameModel model, String timerName,
			int diffTime) {
		HashMap<String, Long> timers = model.getTimers();
		Long lastTimeStamp = timers.get(timerName);
		if (System.currentTimeMillis() - lastTimeStamp >= diffTime) {
			updateTimer(model, timerName);
			return true;
		} else
			return false;
	}

	public static int getRandomDirection(boolean towardsTop) {
		Random random = new Random();
		if(!towardsTop)
			return random.nextInt(360);
		else return random.nextInt(180) + 180;
	}
}
